package site.shihuan.helpdesk.common.config;

import cn.hutool.Hutool;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;

import java.util.Base64;

/**
 * TODO
 *
 * @author 周世焕
 * @Date 2021/1/22 20:58
 */
@Configuration
public class AuthConfigs {

    public static final String AUTHORIZATION_HEADER = "Authorization";

    /**
     * secret key.
     */
    @Value("${auth.token.secret:}")
    private String secretKey;

    /**
     * secret key byte array.
     */
    private byte[] secretKeyBytes;

    /**
     * Token validity time(seconds).
     */
    @Value("${auth.token.expire:18000000}")
    private long tokenValidityInSeconds;

    @Value("${auth.ignore.urls:}")
    private String ignoreUrls;

    public byte[] getSecretKeyBytes() {
        if (secretKeyBytes == null) {
            secretKeyBytes = Base64.getDecoder().decode(secretKey);
        }
        return secretKeyBytes;
    }

    public long getTokenValidityInSeconds() {
        return tokenValidityInSeconds;
    }

}

